home *** CD-ROM | disk | FTP | other *** search
- Path: news.iag.net!news
- From: jatmon@iag.net (John R Buchan)
- Newsgroups: comp.lang.c
- Subject: Re: a tree problem. Complex or not ? is it a classic problem ?
- Date: 14 Jan 1996 01:03:11 GMT
- Organization: Internet Access Group, Orlando, Florida
- Message-ID: <4d9kof$44r@news.iag.net>
- References: <4d60ln$nac@hermes.fundp.ac.be>
- NNTP-Posting-Host: pm4-orl3.iag.net
- X-Newsreader: WinVN 0.99.7
-
- In article <4d60ln$nac@hermes.fundp.ac.be>, fmelo@biq.fundp.ac.be says...
- >
- >Hi Everybody !, I have a complex tree constructed with this structure:
- >
- >struct heavy_atom
- >{
- > int atom_number; /* Atom serial number */
- > char atom_name [8]; /* Atom name */
- > char res_name_3 [8]; /* 3 letters residue name */
- > char res_name_1; /* 1 letter residue name */
- > char chain [8]; /* Chain identifier */
- > int res_number; /* Residue sequence number */
- > float x; /* Orthogonal coordinate for X */
- > float y; /* Orthogonal coordinate for Y */
- > float z; /* Orthogonal coordinate for Z */
- > float occ; /* Occupancy */
- > float temp_f; /* Temperature factor */
- > int atom_type; /* atom type (user definition) */
- > struct heavy_atom *prev_ptr; /* Pointer to previous heavy_atom */
- > struct heavy_atom *next_ptr; /* Pointer to next heavy_atom */
- > struct heavy_atom *ca_ptr; /* Pointer alpha carbon direction */
- > struct heavy_atom *nh2_ptr; /* Pointer in NH2 direction */
- > struct heavy_atom *cooh_ptr; /* Pointer in COOH direction */
- > struct heavy_atom *r1_ptr; /* Pointer in R1 direction */
- > struct heavy_atom *r2_ptr; /* Pointer in R2 direction */
- > struct heavy_atom *r3_ptr; /* Pointer in R3 direction */
- >};
- >
- >Despite of this structure appears like a multidimensional tree with 8
- >potential pointers to another elements, it is not. It is only a
- >tridimensional tree because some pointers will point to NULL. I am using
- >this structure in the way of represent in memory the "real structure" of
- >a molecule (a protein in this case). Every node in the tree represents an
- >atom with all these data and with the pointers that will give the
- >connectivity of each atom with the other ones. Because the maximum
- >connectivity of each atom is 4 (for a carbon atom) this tree will be only
- >tridimensional.
- >
- >After this "short" (some people will find it very long) introduction I
- >will tell my problem.
- >
- >If I am in a node (some atom, doesn't matter which one) and if I define
- >the distance between to nodes as "1", I would like to have an algorithm
- >(or strategy) for identify all the nodes (or atoms) which its distance to
- >the current node is i.e "16". Does exist a strategy or an algorithm for
- >do this ???, is it a classic problem with trees ???.
-
- If I understand you request, something like the following, might fit the
- bill. I haven't tested it (I'm too lazy to write the code to generate a
- molecule to test it on :-) ), but I'm sure that someone in the group will
- point out any glaring errors I missed. It can be rewritten to avoid the
- dist'nth round of recursions.
-
- int CountNodesAtDistance( struct heavy_atom *thisNode, int dist)
- {
- static int currDist = 0;
- int count = 0;
-
- if( dist <= 0) /* just a sefety */
- return 0;
-
- if( currDist == dist) /* node at correct distance, count it */
- count = 1;
- else /* check the next layer out */
- {
- currDist++;
-
- if( thisNode->prev_ptr != NULL)
- count += CountNodesAtDistance( thisNode->prev_ptr, dist);
-
- if( thisNode->next_ptr != NULL)
- count += CountNodesAtDistance( thisNode->next_ptr, dist);
-
- if( thisNode->ca_ptr != NULL)
- count += CountNodesAtDistance( thisNode->ca_ptr, dist);
-
- if( thisNode->nh2_ptr != NULL)
- count += CountNodesAtDistance( thisNode->nh2_ptr, dist);
-
- /* etc. */
-
- currDist--;
- }
-
- return count;
- }
-
-
- int main(void)
- {
- struct heavy_atom *base;
-
- /* of course, you'd nave to created your molecule, so that base is valid */
- CountNodesAtDistance( base, 16);
-
- return (0);
- }
-
-
- --
- John R Buchan -:|:- Looking for that elusive FAQ? ftp to:
- jatmon@mail.iag.net -:|:- rtfm.mit.edu /pub/usenet-by-group/....
-
-